package com.cly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cly.domain.HotSearch;
import com.cly.mapper.HotSearchMapper;
import com.cly.service.HotSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

@Service
public class HotSearchServiceImpl extends ServiceImpl<HotSearchMapper, HotSearch> implements HotSearchService{

    @Autowired
    private HotSearchMapper hotSearchMapper;

    /**
     * 分页查询热搜
     *
     * @param page
     * @param hotSearch
     * @return
     */
    @Override
    public Page<HotSearch> findHotSearchPage(Page<HotSearch> page, HotSearch hotSearch) {
        return hotSearchMapper.selectPage(page, new LambdaQueryWrapper<HotSearch>()
                .eq(ObjectUtils.isEmpty(hotSearch.getStatus()), HotSearch::getStatus, hotSearch.getStatus())
                .like(StringUtils.hasText(hotSearch.getTitle()), HotSearch::getTitle, hotSearch.getTitle())
                .like(StringUtils.hasText(hotSearch.getContent()), HotSearch::getContent, hotSearch.getContent())
                .orderByDesc(HotSearch::getSeq)

        );
    }
}
